﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Pavilion.GameTools
{
    public enum IncrementationAction
    {
        Play,
        Stop
    }

    public class SpeedManipulationTool : GameToolBase
    {
        private static Dictionary<string, Action<SpeedManipulationTool, object>> dataExecutionDictionary;

        public float[] IncrementAmount { set { if (value.Length >= 2) currentIncrementation.IncrementAmount = new Vector2(value[0], value[1]); } }
        public float[] Limit { set { if (value.Length >= 2) currentIncrementation.Limit = new Vector2(value[0], value[1]); } }
        public IncrementationAction IncrementationAction { set { currentIncrementation.UpdateIncrementationAction(value); } }

        private SpeedIncrementation currentIncrementation;

        public SpeedManipulationTool(GameItem parentGameItem) : base(parentGameItem)
        {
            LoadDataExecution();
            currentIncrementation = new SpeedIncrementation(parentGameItem);
        }

        private void LoadDataExecution()
        {
            if (dataExecutionDictionary != null)
                return;

            dataExecutionDictionary = new Dictionary<string, Action<SpeedManipulationTool, object>>();

            dataExecutionDictionary.Add("IncrementAmount", (speedManipulationTool, value) => speedManipulationTool.IncrementAmount = (float[])value);
            dataExecutionDictionary.Add("Limit", (speedManipulationTool, value) => speedManipulationTool.Limit = (float[])value);
            dataExecutionDictionary.Add("IncrementationAction", (speedManipulationTool, value) => speedManipulationTool.IncrementationAction = (IncrementationAction)value);
        }

        public override void UpdateProperty(string propertyName, object propertyValue)
        {
            dataExecutionDictionary[propertyName].Invoke(this, propertyValue);
        }
    }
}
